package task.snake.controller;

import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import task.snake.model.SnakeModel;

/**
 * Class extends class MouseAdapter and handle pressing left and right buttons
 * of mouse.
 * 
 * @author Nadezhda Makarkina
 * 
 */
public class TurnListener extends MouseAdapter {
	private SnakeModel snakeModel;

	/**
	 * Constructor creates TurnListener object and sets snakeModel as parameter.
	 * 
	 * @param snakeModel
	 */
	public TurnListener(SnakeModel snakeModel) {
		this.snakeModel = snakeModel;
	}

	/**
	 * Method handles pressing pressing left and right buttons and calls model's
	 * methods turnLeft() or turnRight().
	 */
	public void mouseClicked(MouseEvent e) {
		int mouseModifiers = e.getModifiers();
		if (mouseModifiers == InputEvent.BUTTON1_MASK) {
			snakeModel.getSnake().turnLeft();
		}
		if (mouseModifiers == InputEvent.BUTTON3_MASK) {
			snakeModel.getSnake().turnRight();
		}
	}
}
